//
//  ZHClinicStatisticsView.m
//  Doctor
//
//  Created by liuzhishan on 15/12/15.
//  Copyright © 2015年 shanshan. All rights reserved.
//

#import "ZHClinicStatisticsView.h"
#import "ZHCircleView.h"
#import "ZHClinicModel.h"

#define IMAGEWIGHT 160
#define IMAGEHEIGH 35
#define IMAGEGAP   72


@interface ZHClinicStatisticsView ()

@property (nonatomic,strong) ZHCircleView *circleView;

@end

@implementation ZHClinicStatisticsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addMyChildViews];
    }
    return self;
}

-(void)addMyChildViews
{
    UIImageView *imageBg = [[UIImageView alloc]init];
    imageBg.image = [UIImage imageNamed:@"transparentV"];
    [self addSubview:imageBg];
    self.image = imageBg;
    
    
    UILabel *lableTitle = [[UILabel alloc]init];
    [lableTitle setMyFramewithX:26 andY:20 andWidth:150 andHeight:50];
    lableTitle.textColor = [UIColor whiteColor];
    lableTitle.font = [UIFont systemFontOfSize:30 * WIDPro - 2];
    
    lableTitle.text = @"诊所统计";
    [self addSubview:lableTitle];
    
    for (int i = 0; i < 3 ;  i++) {
        
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"clinic-%d",i]];
        [imageView setMyFramewithX:60 andY:72+i*IMAGEGAP andWidth:IMAGEWIGHT andHeight:IMAGEHEIGH];
        [self addSubview:imageView];
    }
    
    UILabel * label1=[[UILabel alloc] init];
    [label1 setMyFramewithX:100 andY:74 andWidth:IMAGEWIGHT andHeight:IMAGEHEIGH];
    label1.font=[UIFont systemFontOfSize:20 *WIDPro - 2];
    label1.text=@"未预约到店";
    label1.textAlignment = NSTextAlignmentCenter;
    label1.textColor=[UIColor whiteColor];
    [self addSubview:label1];
    UILabel * label2=[[UILabel alloc] init];
    [label2 setMyFramewithX:100 andY:74+IMAGEGAP andWidth:IMAGEWIGHT andHeight:IMAGEHEIGH];
    label2.font=[UIFont systemFontOfSize:20 *WIDPro - 2];
    label2.text=@"预约到店";
    label2.textAlignment = NSTextAlignmentCenter;
    label2.textColor=[UIColor whiteColor];
    [self addSubview:label2];
    UILabel * label3=[[UILabel alloc] init];
    [label3 setMyFramewithX:100 andY:74+2*IMAGEGAP andWidth:IMAGEWIGHT andHeight:IMAGEHEIGH];
    label3.font=[UIFont systemFontOfSize:20 *WIDPro - 2];
    label3.text=@"预约未到店";
    label3.textAlignment = NSTextAlignmentCenter;
    label3.textColor=[UIColor whiteColor];
    [self addSubview:label3];
    
    UIImageView *bgimage = [[UIImageView alloc]init];
    [bgimage setMyFramewithX:23 andY:528 andWidth:250 andHeight:64];
    bgimage.image = [UIImage imageNamed:@"home-4"];
    [self addSubview:bgimage];
    
    
    UIButton *btnDetails = [UIButton buttonWithType:UIButtonTypeCustom];
    
    
    [btnDetails setMyFramewithX:280 andY:530 andWidth:90 andHeight:40];
    [btnDetails setBackgroundImage:[UIImage imageNamed:@"clinic-details"] forState:UIControlStateNormal];
    [self addSubview:btnDetails];
    [btnDetails addTarget:self action:@selector(btnClick) forControlEvents:(UIControlEventTouchUpInside)];
    
    
}

-(void)setClinicModel:(ZHClinicModel *)clinicModel
{
    _clinicModel = clinicModel;
    
    CGFloat all = [clinicModel.patienterNumber floatValue];
    CGFloat appointArrive   = [clinicModel.appointmentNumber floatValue];
    CGFloat  appointAll = [clinicModel.appointNumber floatValue];
    CGFloat  appointNotArrive = appointAll - appointArrive;
    
    
    
    
//    CGFloat all = arc4random() %40 + 40;
//    CGFloat appointArrive  =  arc4random() %10 + 10;
//    CGFloat  appointAll =  arc4random() %20 + 20;
    
    
    
    if (all == 0) {
        
        CGFloat first  =    0;
        CGFloat second =   0;
        CGFloat three  =    0;
        
        [self.circleView setInitialAngle:-M_PI_4 andFirstProportion:first andSecondProportion:second andThree:three];
  
        
        return;
        
    }
    CGFloat first =   (all - appointAll)/all;
    CGFloat second =   appointArrive / all;
    CGFloat three = 1.0 - first - second;
    
    [self.circleView setInitialAngle:-M_PI_4 andFirstProportion:first andSecondProportion:second andThree:three];

    
    
}

-(ZHCircleView *)circleView
{
    if (_circleView == nil) {
        
         _circleView = [[ZHCircleView alloc]init];
        [_circleView setMyFramewithX:130 andY:300 andWidth:190 andHeight:190];
        [self addSubview:_circleView];
        
    }
    
    return _circleView;
   
}

-(void)btnClick
{
    [self.dele pushMyChooseController:1];
}

@end
